package com.xhui.vimarket.zkplus.zul.attr.ada.impl;

import lombok.Getter;
import lombok.Setter;

import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Button;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Decimalbox;
import org.zkoss.zul.Div;
import org.zkoss.zul.Doublebox;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Menu;
import org.zkoss.zul.Menubar;
import org.zkoss.zul.Menupopup;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Timebox;
import org.zkoss.zul.Toolbarbutton;
import org.zkoss.zul.Tree;

import com.xhui.crm.common.util.string.StrUtil;com.xhui.vimarket.zkplusui.vimarket.zkplus.util.Compcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zulcom.xhui.vimarket.zkplusda;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.AttrTmpl;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.impl.AttrTmplImpl;
import com.xhui.vicom.xhui.vimarket.zkplusul.attr.mod.impl.AttrBaseComp;
import com.xhuicom.xhui.vimarket.zkpluss.zul.attr.mod.impl.AttrButtonTextComp;
imcom.xhui.vimarket.zkplusimarket.zkplus.zul.attr.mod.impl.AttrDivExtComp;com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attr.modcom.xhui.vimarket.zkplusordTwoComp;
import com.xhui.vimarket.zkplus.zul.panel.GroupPanel;
import com.xhui.vimarket.zkplus.zul.textbox.TextboxPlus;

/**
 * 默认属性界面控件模式适配.
 * 取空属性实例方案：全部不生成
 * 按钮文本，composer方案：采用默认的值显示和设置composer,或根据传入的值设置
 * checkbox，composer方案：采用无composer
 * groupbox，composer方案：采用无composer
 * 
 * @author wuyx
 * @version Revision 1.0.0
 * 
 */
public class DefaultAttrAda implements AttrAda {
    
    /**
     * ins.
     */
    @SuppressWarnings("unused")
    private static AttrAda ins            = new DefaultAttrAda();
    /**
     * 是否配置预览.
     */
    @Getter
    @Setter
    private boolean        settingPreview = false;
    
    /**
     * instance.
     * @return AttrAda
     */
    public static AttrAda instance() {
        return new DefaultAttrAda();
    }
    
    /**
     * 构造函数.
     */
    protected DefaultAttrAda() {
    }
    
    @Override
    public Component getAttrTmplCompStr(final String displayMode, final AttrTmpl attrTmpl,
        final String sComposer, final String param1, final String param2, Component parentComp) {
        if (displayMode == null) {
            return null;
        } else if (AttrTmplImpl.MODE_CHECKBOX.equals(displayMode)
            || AttrTmplImpl.MODE_CHECKBOX_BYINST.equals(displayMode)) {
            return ComposerUtil.bindParent(new Checkbox(), parentComp);
        } else if (AttrTmplImpl.MODE_BUTTONTEXT.equals(displayMode)) {
            String sDefComposer = AttrButtonTextComp.BTN_DEF_COMPOSER;
            if (!this.isSettingPreview() && !"".equals(StrUtil.strnull(sComposer))) {
                // 非预览 并且 有配置情况下采用配置的数据 
                sDefComposer = sComposer;
            }
            Button button = new Button();
            ComposerUtil.bindComposer(button, sDefComposer, parentComp);
            return button;
        } else if (AttrTmplImpl.MODE_MENUTEXT.equals(displayMode)) {
            String sDefComposer = AttrButtonTextComp.BTN_DEF_COMPOSER;
            if (!this.isSettingPreview() && !"".equals(StrUtil.strnull(sComposer))) {
                // 非预览 并且 有配置情况下采用配置的数据 
                sDefComposer = sComposer;
            }
            Button button = new Button();
            ComposerUtil.bindComposer(button, sDefComposer, parentComp);
            return button;
            // return "<button apply=\"" + sDefComposer + "\" />";
        } else if (Attcom.xhui.vimarket.zkplusGROUPBOX.equals(displayMode)) {
            //            String str = "<div use=\"com.xhui.vimarket.zkplus.zul.panel.GroupPanel\">"
            //                + "<div><span><label /></span><span></span></div></div>";
            //            Component comp = Executions.createComponentsDirectly(str, null, null, null);
            GroupPanel comp = new GroupPanel();
            comp.onCreate();
            return comp;
        } else if (AttrTmplImpl.MODE_SELECTLIST.equals(displayMode)) {
            return ComposerUtil.bindParent(new Listbox(), parentComp);
        } else if (AttrTmplImpl.MODE_DIVEXT.equals(displayMode)) {
            String sDefComposer = AttrDivExtComp.DIV_DEF_COMPOSER;
            if (!this.isSettingPreview() && !"".equals(StrUtil.strnull(sComposer))) {
                // 非预览 并且 有配置情况下采用配置的数据 
                sDefComposer = sComposer;
            }
            Div div = new Div();
            ComposerUtil.bindComposer(div, sDefComposer, parentComp);
            return div;
            // return "<div apply=\"" + sDefComposer + "\" />";
        } else if (AttrTmplImpl.MODE_PASSWORDTWO.equals(displayMode)) {
            String sDefComposer = AttrPasswordTwoComp.PWD_PARENT_BOX_COMPOSER;
            if (!this.isSettingPreview() && !"".equals(StrUtil.strnull(sComposer))) {
                // 非预览 并且 有配置情况下采用配置的数据 
                sDefComposer = sComposer;
            }
            Div div = new Div();
            ComposerUtil.bindComposer(div, sDefComposer, parentComp);
            return div;
            // return "<div apply=\"" + sDefComposer + "\" />";
        } else if (AttrTmplImpl.MODE_DATE.equals(displayMode)) {
            return ComposerUtil.bindParent(new Datebox(), parentComp);
            // return "<datebox />";
        } else if (AttrTmplImpl.MODE_DATETIME.equals(displayMode)) {
            return ComposerUtil.bindParent(new Datebox(), parentComp);
            // return "<datebox />";
        } else if (AttrTmplImpl.MODE_TIME.equals(displayMode)) {
            return ComposerUtil.bindParent(new Timebox(), parentComp);
            // return "<timebox />";
        } else if (AttrTmplImpl.MODE_TEXT.equals(displayMode)) {
      com.xhui.vimarket.zkplusmposerUtil.bindParent(new TextboxPlus(), parentComp);
            // return "<textbox use=\"com.xhui.vimarket.zkplus.zul.textbox.TextboxPlus\" />";
        } else if (AttrTmplImpl.MODE_INT.equals(displayMode)) {
            return ComposerUtil.bindParent(new Intbox(), parentComp);
            // return "<intbox />";
        } else if (AttrTmplImpl.MODE_DOUBLE.equals(displayMode)) {
            return ComposerUtil.bindParent(new Doublebox(), parentComp);
        } else if (AttrTmplImpl.MODE_MONEY.equals(displayMode)
            || AttrTmplImpl.MODE_DISCOUNT.equals(displayMode)) {
            return ComposerUtil.bindParent(new Decimalbox(), parentComp);
        } else if (AttrTmplImpl.MODE_TIME.equals(displayMode)) {
            return ComposerUtil.bindParent(new Timebox(), parentComp);
            // return "<timebox />";
        } else if (AttrTmplImpl.MODE_CHECKBOX.equals(displayMode)) {
            return ComposerUtil.bindParent(new Checkbox(), parentComp);
            // return "<checkbox />";
        } else if (AttrTmplImpl.MODE_PASSWORD.equals(displayMode)) {
            return ComposerUtil.bindParent(new Textbox(), parentComp);
            // return "<textbox />";
        } else if (AttrTmplImpl.MODE_NULLVAL.equals(displayMode)) {
            return ComposerUtil.bindParent(new Div(), parentComp);
            // return "<div />";
        } else if (AttrTmplImpl.MODE_SELECTTREE.equals(displayMode)) {
            return ComposerUtil.bindParent(new Tree(), parentComp);
        } else if (AttrTmplImpl.MODE_MULTISUB.equals(displayMode)) {
            return ComposerUtil.bindParent(new Listbox(), parentComp);
        }
        return null;
    }
    
    @Override
    public Component getAttrMenuCompStr(String displayMode, AttrTmpl attrTmpl, String sComposer,
        String param1, String param2, Component parentComp) {
        Menubar menubar = (Menubar) ComposerUtil.bindParent(new Menubar(), parentComp);
        menubar.setAutodrop(true);
        menubar.setStyle("border:0px; background: transparent;");
        menubar.setOrient("vertical");
        Menu menu = new Menu();
        Menupopup menupopup = new Menupopup();
        menu.setParent(menubar);
        menupopup.setParent(menu);
        return menubar;
        //        return "<menubar autodrop=\"true\" " + "style=\"border:0px; background: transparent;\" "
        //            + "orient=\"vertical\">" + "<menu><menupopup></menupopup></menu></menubar>";
    }
    
    @Override
    public Component getAttrResetStr(final String displayMode, final AttrTmpl attrTmpl,
        final String sComposer, final String param1, final String param2, Component parentComp) {
        if (displayMode == null) {
            return null;
        } else if (AttrTmplImpl.MODE_TIME.equals(displayMode)) {
            Toolbacom.xhui.vimarket.zkplusbutton = new Toolbarbutton();
            ComposerUtil.bindComposer(toolbarbutton,
                "com.xhui.vimarket.zkplus.zul.acom.xhui.vimarket.zkpluseResetCompoer", parentComp);
            return toolbarbutton;
            // return "<toolbarbutton apply=\"com.xhui.vimarket.zkplus.zul.attr.evt.AttrTimeResetCompoer\" />";
        }
        return null;
    }
    
    @Override
    public Component getAttrPasswordTextbox2Str(String displayMode, AttrTmpl attrTmpl,
        String sComposer, String param1, String param2, Component parentComp) {
        return ComposerUtil.bindParent(new Textbox(), parentComp);
    }
    
    @Override
    public boolean isCreateNullAttrInst(final String displayMode, final AttrTmpl attrTmpl) {
        return false;
    }
    
    @Override
    public String isDispReset(final String displayMode, final AttrTmpl attrTmpl,
        final String sComposer, final String param1, final String param2) {
        return null;
    }
    
    @Override
    public boolean isDispRulebar() {
        return true;
    }
    
    @Override
    public int getSortType() {
        return AttrBaseComp.SORT_BY_ORDER;
    }
    
    @Override
    public boolean isViewMode() {
        return false;
    }
    
}
